package com.redpack.redpost.struts.action.admin;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.redpack.redpost.struts.form.admin.mercanciasForm;
import com.redpack.redpost.util.dao.*;
import com.redpack.redpost.util.to.*;

public class editarmercancias extends Action {
	
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request, 
			HttpServletResponse response) throws Exception {
		
		/*boolean logginVal = generalUtil.isLoggedIn(request);
		if(logginVal!=true)
			return mapping.findForward("noLogin") ;*/
		
		mercanciasForm f = (mercanciasForm)form;
		
		if( f != null ){
			if( f.getAcc().equals("2") ){
				MercanciaImporteDao.eliMerc(f.getCve_mercancia());
			}
			
			if( f.getAcc().equals("1") ){
				//String[][] idiomas = generalUtil.obtieneIdiomas();				
				//request.setAttribute("idiomas", idiomas);
		
				MercanciaImporteTo mercancia_info = MercanciaImporteDao.getMercancia(f.getCve_mercancia());
				
				request.setAttribute("cve_mercancia", ""+mercancia_info.getCve_mercancia());
				request.setAttribute("nombre", ""+mercancia_info.getNombre());
				request.setAttribute("nombre_eng", ""+mercancia_info.getNombre_eng());
				request.setAttribute("limite_inferior", ""+mercancia_info.getLimite_inferior());
				request.setAttribute("limite_superior", ""+mercancia_info.getLimite_superior());
				request.setAttribute("porcentaje_impuesto_import", ""+mercancia_info.getPorcentaje_impuesto_import());
				

				return mapping.findForward("edit") ;
			}
		}
		
		List mercancias = MercanciaImporteDao.getMercancias();
		request.setAttribute("mercancias", mercancias);
		
		return mapping.findForward("success") ;
	}

}